package com.ejd.web.vo.customer;

import java.io.IOException;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.SessionScoped;
import javax.faces.bean.ViewScoped;
import javax.faces.component.UIViewRoot;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.faces.event.ValueChangeEvent;
import javax.faces.model.SelectItem;

import net.sf.cglib.beans.BeanCopier;

import com.ejd.service.IColorService;
import com.ejd.service.IConsultationService;
import com.ejd.service.ICustomerService;
import com.ejd.service.IOrderService;
import com.ejd.service.IGoodsService;
import com.ejd.utils.DESPlusUtil;
import com.ejd.utils.MessageFactory;
import com.ejd.utils.SortManagerDelegate;
import com.ejd.utils.SpringFacesUtil;
import com.ejd.web.bo.impl.Color;
import com.ejd.web.bo.impl.Consultation;
import com.ejd.web.bo.impl.Customer;
import com.ejd.web.bo.impl.Order;
import com.ejd.web.bo.impl.Goods;
import com.ejd.web.bo.impl.GoodsProperties;
import com.ejd.web.constant.EjdConstants;
import com.ejd.web.constant.ManageBeanConstants;
import com.ejd.web.constant.SpringBeanConstants;
import com.ejd.web.vo.common.ColorVo;
import com.ejd.web.vo.common.ConsultationPage;
import com.ejd.web.vo.common.ConsultationVo;
import com.ejd.web.vo.common.CustomerVo;
import com.ejd.web.vo.common.OrderVo;
import com.ejd.web.vo.common.GoodsPropertiesVo;
import com.ejd.web.vo.common.GoodsVo;
import com.ejd.web.vo.genl.GenerateVerifyCodeBean;
@ManagedBean(name="orderPay")
@ViewScoped

public class OrderPayPageBean implements java.io.Serializable {
	private static final long serialVersionUID = -8106629465344224770L;
	
	private String orderId;
	
	private OrderVo order;
	
	private String errorMessages;
	
	public String getOrderId() {
		return orderId;
	}

	public void setOrderId(String orderId) {
		this.orderId = orderId;
	}

	public OrderVo getOrder() {
		return order;
	}

	public void setOrder(OrderVo order) {
		this.order = order;
	}

	public String getErrorMessages() {
		return errorMessages;
	}

	public void setErrorMessages(String errorMessages) {
		this.errorMessages = errorMessages;
	}

	public OrderPayPageBean() throws IOException,Exception{
		String orderId =(String) SpringFacesUtil.getRequestParameter("orderId");
		if (null == orderId || "".equals(orderId) || "null".equals(orderId)) {
			SpringFacesUtil.redirectPage(EjdConstants.INDEX_HTML);
			
		}else {
			DESPlusUtil desUtil = new DESPlusUtil();
			orderId = desUtil.decrypt(orderId);
			this.setOrderId(orderId);
			IOrderService<Order,Long> orderService = (IOrderService<Order,Long>)SpringFacesUtil.getSpringBean(SpringBeanConstants.ORDER_SERVICE_BEAN_NAME);
			orderService.setEntityClass(Order.class);
			orderService.setPKClass(Long.class);
			Order theOrder = orderService.findUniqueBy("orderId", orderId);
			if (null != theOrder) {
				LoginCustomerPageBean loginCustomerPage = (LoginCustomerPageBean)SpringFacesUtil.getManagedBean(ManageBeanConstants.LOGIN_CUSTOMER_PAGE_BEAN_NAME);
				Customer orderOfCustomer = theOrder.getCustomer();
				if (!(loginCustomerPage.getCustomerInfo().getCustomerId().equals(orderOfCustomer.getCustomerId()))) {
					String authorizN18 = MessageFactory.getMessage(EjdConstants.USER_BUNDLE_NAME,"order.view.not.authorized", FacesMessage.SEVERITY_ERROR).getDetail();
					this.setErrorMessages(authorizN18);
					this.setOrder(new OrderVo());
				} else {
					OrderVo theOrderVo = new OrderVo();
					theOrderVo.setOrderId(orderId);
					theOrderVo.setNeedPayment(theOrder.getNeedPayment());
					theOrderVo.setPaymentType(theOrder.getPaymentType());
					theOrderVo.setPaymentTypeDisplay(theOrder.getPaymentTypeDisplay());
					theOrderVo.setPaymentId(theOrder.getPaymentId());
					theOrderVo.setPaymentName(theOrder.getPaymentName());
					theOrderVo.setPaymentExpense(theOrder.getPaymentExpense());
					theOrderVo.setPaymentDescription(theOrder.getPaymentDescription());
					theOrderVo.setPaymentTypeId(theOrder.getPaymentTypeId());
					theOrderVo.setStatus(theOrder.getStatus());
					this.setOrder(theOrderVo);
				}
			} else {
				SpringFacesUtil.redirectPage(EjdConstants.INDEX_HTML);
			}
		}
	}
	
	public void goDetailPage(ActionEvent evt) {
		/*String code =(String) SpringFacesUtil.getRequestParameter("code");
		System.out.println(code);
		this.setCode(code);*/
	}
	public String goDetailPage1(){
		/*if (this.checkJspExist(this.getCode()+".xhtml", "/jspLayout/shoes") && this.checkJspExist(this.getCode()+"Detail.xhtml", "/jspLayout/shoes/sub") ) {
			return this.getCode()+"?faces-redirect=true&primaryCategoryCode="+this.getPrimaryCategoryCode()+"&code="+this.getCode()+"&productId="+this.getProductId();
		} else {
			return "/WEB-INF/"+EjdConstants.NO_PRODUCT_DETAIL_PAGE;
		}*/
		return null;
	}
	public String goaction() throws IOException{
		SpringFacesUtil.redirectPage(EjdConstants.INDEX_HTML);
		System.out.println("dddddddd");
		return null;
	}
	
}
